/**
 * 设置cookie,默认7天过期
 * @param {*} cname 
 * @param {*} cvalue 
 * @param {*} exSeconds  过期时间（秒）
 */
const setCookie = (cname, cvalue, exSeconds = 7 * 24 * 60 * 60)=> {
	const d = new Date();
	d.setTime(d.getTime() + (exSeconds * 1000));
	const expires = "expires=" + d.toGMTString();
	document.cookie = cname + "=" + cvalue + ';' + expires + "path=/";
}

/**
 * 获取cookie
 * @param {*} cname 
 */
const getCookie = (cname)=> {
	const name = cname + "=";
	const ca = document.cookie.split(';');
	for(let i = 0; i < ca.length; i++) {
		const c = ca[i].trim();
		if(c.indexOf(name) == 0) return c.substring(name.length, c.length);
	}
}

/**
 * 移除某项cookie
 * @param {*} cname 
 */
const removeCookie = ()=> {
	setCookie(cname, '', -365);
}

export default {
    getCookie, setCookie, removeCookie
}